/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminFeeConfigInfo: {
                feeConfigs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                feeName: '',
                paymentCds: [],
                billTypes: [],
                isDefaults: [],
                curPage: DEFAULT_PAGE,
                conditions: {
                    configId: '',
                    feeFlag: '',
                    billType: '',
                    feeName: '',
                    feeTypeCd: '',
                    isDefault: 'F',
                    paymentCd: '',
                    deductFrom: ''
                }
            }
        },
        _initMethod: function () {
            vc.emit('communityFeeTypeTree', 'initCommunityFeeTypeTree',{
                callName:'adminFeeConfig'
            });
            $that._listAdminFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            //关联字典表费用类型
            
            //关联字典表付费类型
            vc.getDict('pay_fee_config', 'payment_cd', function (_data) {
                $that.adminFeeConfigInfo.paymentCds = _data;
            });
            //关联字典表费用项
            vc.getDict('pay_fee_config', 'is_default', function (_data) {
                $that.adminFeeConfigInfo.isDefaults = _data;
            })
        },
        _initEvent: function () {
            vc.on('adminFeeConfig', 'selectCommunity', function (_param) {
                $that.adminFeeConfigInfo.conditions.communityId = _param.communityId;
                $that.adminFeeConfigInfo.conditions.feeTypeCd = '';
                $that.adminFeeConfigInfo.conditions.feeFlag = '';
                $that._listAdminFeeConfigs(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminFeeConfig', 'selectFeeTypeCd', function (_param) {
                $that.adminFeeConfigInfo.conditions.communityId = _param.communityId;
                $that.adminFeeConfigInfo.conditions.feeTypeCd = _param.feeTypeCd;
                $that.adminFeeConfigInfo.conditions.feeFlag = '';
                $that._listAdminFeeConfigs(DEFAULT_PAGE,DEFAULT_ROWS);

            });
            vc.on('adminFeeConfig', 'selectFeeFlag', function (_param) {
                $that.adminFeeConfigInfo.conditions.communityId = _param.communityId;
                $that.adminFeeConfigInfo.conditions.feeTypeCd = _param.feeTypeCd;
                $that.adminFeeConfigInfo.conditions.feeFlag = _param.feeFlag;
                $that._listAdminFeeConfigs(DEFAULT_PAGE,DEFAULT_ROWS);
            });
            vc.on('adminFeeConfig', 'listFeeConfig',
                function (_param) {
                    $that._listAdminFeeConfigs($that.adminFeeConfigInfo.curPage, DEFAULT_ROWS);
                });
            vc.on('pagination', 'page_event',
                function (_currentPage) {
                    $that.adminFeeConfigInfo.curPage = _currentPage;
                    $that._listAdminFeeConfigs(_currentPage, DEFAULT_ROWS);
                });
        },
        methods: {
            //查询方法
            _listAdminFeeConfigs: function (_page, _rows) {
                $that.adminFeeConfigInfo.conditions.page = _page;
                $that.adminFeeConfigInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminFeeConfigInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/feeConfig.queryAdminFeeConfigs',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminFeeConfigInfo.total = _json.total;
                        $that.adminFeeConfigInfo.records = _json.records;
                        $that.adminFeeConfigInfo.feeConfigs = _json.feeConfigs;
                        vc.emit('pagination', 'init', {
                            total: $that.adminFeeConfigInfo.records,
                            dataCount: $that.adminFeeConfigInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //重置方法
            _resetListFeeConfigs: function () {
                $that.adminFeeConfigInfo.conditions.configId = '';
                $that.adminFeeConfigInfo.conditions.feeName = '';
                $that.adminFeeConfigInfo.conditions.feeTypeCd = '';
                $that.adminFeeConfigInfo.conditions.feeFlag = '';
                $that.adminFeeConfigInfo.conditions.paymentCd = '';
                $that.adminFeeConfigInfo.conditions.billType = '';
                $that.adminFeeConfigInfo.conditions.isDefault = '';
                $that.adminFeeConfigInfo.conditions.deductFrom = '';
                $that._listAdminFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
           
            //查询
            _queryFeeConfigMethod: function () {
                $that._listAdminFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetFeeConfigMethod: function () {
                $that._resetListFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.adminFeeConfigInfo.moreCondition) {
                    $that.adminFeeConfigInfo.moreCondition = false;
                } else {
                    $that.adminFeeConfigInfo.moreCondition = true;
                }
            },
            _settingConfigDiscount: function (_feeConfig) {
                vc.jumpToPage('/#/pages/property/payFeeConfigDiscountManage?configId=' + _feeConfig.configId + "&feeName=" + _feeConfig.feeName);
            },
            swatchFeeTypeCd: function (item) {
                $that.adminFeeConfigInfo.conditions.feeTypeCd = item.statusCd;
                $that._listAdminFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openFeeConfigDetail: function (_feeConfig) {
                window.open('/#/pages/fee/feeConfigDetail?configId=' + _feeConfig.configId)
            }
        }
    });
})(window.vc);